package com.demo;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class RedisClusterDemo {

    public static void main(String[] args) {
        JedisPoolConfig config = new JedisPoolConfig();
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7001));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7002));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7003));
////        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7004));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7011));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7012));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7013));
//        jedisClusterNode.add(new HostAndPort("127.0.0.1", 7014));
        JedisCluster jcd = new JedisCluster(jedisClusterNode, config);
        for (int i = 0; i < 200; i++) {
            jcd.set("test:"+i, "redis-cluster-demo"+i);
            String value = jcd.get("test:"+i);
            System.out.println(value);
        }

    }
}
